-- UICommonIntroduce
-- Created by chengb Jan/17/2015
-- 通用说明界面

UICommonIntroduce = class("UICommonIntroduce", function()
    return cc.Layer:create();
end);

function UICommonIntroduce.create(brief)
    return UICommonIntroduce.new(brief);
end

-- 构造函数
function UICommonIntroduce:ctor(brief)
    self:setName("UICommonIntroduce");
    local node = cc.CSLoader:createNode("layout/common/CommonIntroduce.csb");
    self:addChild(node);
    self.node = node;
    self.brief = brief;

    self:setLocalZOrder(UIMgr.TOP_MENU_ZORDER + 2);

    -- 注册返回按钮点击事件
    local btnBack = findChildByName(node, "BT/btn_back");
    local function onBackClick(sender, eventType)
        if eventType == ccui.TouchEventType.ended then
            AudioM.playFx("button_return");
            -- 关闭当前界面
            UIMgr.getCurrentScene():removeFormByName("UICommonIntroduce");
        end
    end
    AddBackEventHandler(self, btnBack, onBackClick);
    TextStyleM.setTextStyle(btnBack, TextStyleM.TEXT_SIZE_MIDDLE, TextStyleM.TEXT_COLOR_BROWN_YELLOW, true);
    btnBack:setTitleText(getLocStr("btn_text_back"));

    -- 注册背景点击事件
    local bg = findChildByName(node, "bg/bgImg");
    local function onBgClick(sender, eventType)
        if eventType == ccui.TouchEventType.ended then
            AudioM.playFx("button_return");
            -- 关闭当前界面
            UIMgr.getCurrentScene():removeFormByName("UICommonIntroduce");
        end
    end
    bg:addTouchEventListener(onBgClick);

    self:redraw();

    self:resize();
end

-- 适配
function UICommonIntroduce:resize()
    local node = self.node;

    -- bg居中显示并充满整个屏幕
    AlignM.fitToScreen(node, "bg");

    -- CT居中并缩放至合适大小
    AlignM.alignToCenter(node, "CT");

    -- BT置于底部并缩放至合适大小
    AlignM.alignToBottomCenter(node, "BT");
end

-- 重绘
function UICommonIntroduce:redraw()
    local briefLabel = findChildByName(self.node, "CT/brief");
    TextStyleM.setTextStyle(briefLabel, TextStyleM.TEXT_SIZE_SMALL, TextStyleM.TEXT_COLOR_DARK_BROWN);
    briefLabel:setString(tostring(self.brief));
end





